package com.bruce.nettyDemo.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * Created by bruce on 19/3/30 -- 9:39
 */
//初始化器，channel注册以后，会执行里面相应的初始化的方法
public class HttpServerInit extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //通过channel去获取对应的管道(管道类似于是一个拦截器)
        ChannelPipeline pipeline = socketChannel.pipeline();
        //设置netty自带的处理器，httpServer的编解码器(通过管道添加handler)
        pipeline.addLast("HttpServerCodec", new HttpServerCodec());
        //添加自定义的handler
        pipeline.addLast("customHandler", new HttpHandler());

    }
}
